<?php
/**
 * Created by PhpStorm.
 * User: crstu
 * Date: 2016/5/29
 * Time: 19:07
 */

namespace common\widgets;

use common\assets\SimditorAsset;
use yii\helpers\Html;
use yii\widgets\InputWidget;

class Simditor extends InputWidget
{

    public $elementID;

    public $toolbar;

    public $toolbarFloat;

    public $toolbarHidden;

    public $defaultImage;

    public $tabIndent;

    public $params;

    public $upload;

    public $pasteImage;

    
    public function init(){

        parent::init();
        SimditorAsset::register($this->getView());

        $this->options['class'] = 'form-control';
        
    }
    
    public function run()
    {
        parent::run();
        if($this->hasModel()){
            echo Html::activeTextarea($this->model, $this->attribute, $this->options);
        }else{
            echo Html::textarea($this->name, '', $this->options);
        }

        $js =  "var editor = new Simditor({
                        textarea: $('#".$this->options['id']."'),
                        upload: {url:'/upload/qiniu-editor.html'},
                        toolbarFloatOffset: 46,
                        cleanPaste: true,
                        toolbar: ['title','bold','italic','underline','strikethrough','fontScale','color','ol','ul','blockquote','code','table','link','image','hr','indent','outdent','alignment'],
                        upload: {url:'/upload/qiniu-editor.html'}
                    });";

        $this->getView()->registerJs($js);
    }
    
    

}